﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ajax.BLL;
using Newtonsoft;
using Newtonsoft.Json;
using System.Web.Services;
using Habito.Helper;
using System.Text;

namespace Habito
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

			Ajax.BLL.References refs = new Ajax.BLL.References();
			StringBuilder temp = new StringBuilder();
			int i = 0;
			foreach (var item in refs.GetModelList(""))
			{
				string temps = item.ProjectName;
				if (item.ProjectName.Length > 36)
				{
					item.ProjectName = item.ProjectName.Substring(0, 36) + "...";
				}
				i++;
				if (i > 6)
				{
					break;
				}
				temp.AppendFormat("<span style='cursor:pointer;  text-align:left; overflow:hidden; padding-left:15px; padding-top:3px; display:block;height:23px;line-height:25px;' tt='1' tt1='{1}' title='{2}'>{0}</span>", item.ProjectName, item.ID, temps);
			}
			ViewState["LatestReferences"] = temp.ToString();


			Ajax.BLL.Products product = new Ajax.BLL.Products();
			StringBuilder temp1 = new StringBuilder();
			i = 0;
			foreach (var item in product.GetModelList(""))
			{
				string temps = item.ProductName;
				if (item.ProductName.Length > 36)
				{
					item.ProductName = item.ProductName.Substring(0, 36) + "...";
				}
				i++;
				if (i > 6)
				{
					break;
				}
				temp1.AppendFormat("<span style='cursor:pointer; text-align:left; overflow:hidden;padding-left:15px;padding-top:3px; display:block;height:23px;line-height:25px;'  tt='2' tt1='{1}' title='{2}'>{0}</span>", item.ProductName, item.ID, temps);
			}
			ViewState["NewProducts"] = temp1.ToString();

			Ajax.BLL.Solutions solution = new Ajax.BLL.Solutions();
			StringBuilder temp3 = new StringBuilder();
			i = 0;
			foreach (var item in solution.GetModelList(""))
			{
				string temps = item.Title;
				if (item.Title.Length > 36)
				{
					item.Title = item.Title.Substring(0, 36) + "...";
				}
				i++;
				if (i > 6)
				{
					break;
				}
				temp3.AppendFormat("<span style='cursor:pointer; padding-left:15px;padding-top:3px;  overflow:hidden; text-align:left;display:block;height:25px;line-height:23px; '  tt='3' tt1='{1}' title='{2}'>{0}</span>", item.Title, item.ID, temps);
			}
			ViewState["NewSolutions"] = temp3.ToString();


			if (Request.QueryString["AllProductClass"] != null)
			{

			}
		}

		protected override void OnInit(EventArgs e)
		{
			if (Request.QueryString["GetData"] != null)
			{
				Response.Write("1");
				Response.End();
			}

			if (Request.QueryString["GetProducts"] == "1")
			{
				Ajax.BLL.Products products = new Ajax.BLL.Products();
				List<Ajax.Model.Products> list = products.GetModelList(" ShowInIndex= 1 AND ImagePath IS NOT NULL ");
				Response.Write(JsonConvert.SerializeObject(list));
				Response.End();
			}

			base.OnInit(e);
		}

		[WebMethod]
		public static string GetData()
		{
			Ajax.BLL.Products pro = new Ajax.BLL.Products();
			List<Ajax.Model.Products> list = new List<Ajax.Model.Products>();
			list = pro.GetModelList("");

			string result = "";
			result = JsonConvert.SerializeObject(list);

			return result;

		}



	}
}